<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<form class="layui-form">
  <!--  <input type="text" name="emailAddress"/>-->

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" id="emailAddres" class="layui-input"
                    placeholder="邮箱" name="emailAddress" value=""
                   lay-verify="email">

        </div>
        </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addUser">立即提交</button>
        </div>
    </div>
   <!-- <input type="bottom" value="提交">-->



</form>

</body>
<script th:src="@{/src/layui.js}"></script>
<script>

    layui.use(['form','layer','jquery'],function () {
        var form = layui.form,

            $ = layui.jquery,
            layer = layui.layer;


        //添加
        form.on('submit(addUser)',function (data) {
            console.log(data.field.emailAddress);
            var emailAddres=data.field.emailAddress;
            layer.msg(emailAddres);
            $.ajax({
                url:'/email?emailAddres='+emailAddres,
                type:'post',
                data:data.field,
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('邮箱发送成功',{icon:1},function () {
                            /*parent.layer.closeAll("iframe");
                            parent.location.reload();*/
                            location.href="/sys/isCode"
                        });
                    }else{
                        layer.msg(res.message,{icon:5});
                    }
                }
            })
            return false; //表单不提交，通过ajax的方式异步提交数据。
        })
    })





</script>
</html>